package demo1;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Demo6 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("John Doe,john@doe.com");
        list.add("Bob Smith,bob@smith.com");
        list.add("Alice Johnson,alice@johnson.com");
        Map<String, String> ret = func(list);
        for(Map.Entry<String, String> entry : ret.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }

    public static Map<String, String> func(List<String> list) {
        Map<String ,String> map = new HashMap<>();
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            int j = 0;
            String tmp1 = "";
            for(j = 0; j < s.length(); j++) {
                if(s.charAt(j) == ',') {
                    break;
                } else {
                    tmp1 += s.charAt(j);
                }
            }
            String tmp2 = "";
            j++;
            while(j < s.length()) {
                tmp2 += s.charAt(j);
                j++;
            }
            map.put(tmp2,tmp1);
        }
        return map;
    }
}
